<?php
include_once('./Evaluator.php.inc');
include_once('./QueryResult.php.inc');
class SearchResults {
	private $results = array();
	private $avgRecall= array();
	private $avgF1 = array();
	private $avgPrecision = array();
	//private $model = array();
	public function SearchResults(){
		$this->results[Models::BOOL] = $boolResults = array();
		$this->results[Models::VSM_BOOL] = $vsmBoolResults = array();
		$this->results[Models::VSM] = $vsmResults = array();
		$this->results[Models::VSM_PAGERANK] = $vsmPagerankResults = array();
	}
	/*public function setModel($model){
		$this->model=$model;
	}*/
	public function addQueryResult($model, $query, $queryResult){
		$this->results[$model][$query] = $queryResult;
	}
	public function calculateResults(){
		foreach($this->results as $model => $dummy){
			$queryResults=$this->results[$model];
			$sumRecall=0;
			$sumF1=0;
			$sumPrecision=0;
			foreach($queryResults as $query => $queryResult){
				$sumF1+=$queryResult->f1Score;
				$sumRecall+=$queryResult->recall;
				$sumPrecision+=$queryResult->precision;
			}
			$nbrOfQueryResults=count($queryResults);
			if($nbrOfQueryResults!=0){
				$this->avgF1[$model]=$sumF1/$nbrOfQueryResults;
				$this->avgRecall[$model]=$sumRecall/$nbrOfQueryResults;
				$this->avgPrecision[$model]=$sumPrecision/$nbrOfQueryResults;
			}else{
				$this->avgF1[$model]=0;
				$this->avgRecall[$model]=0;
				$this->avgPrecision[$model]=0;
			}
			
		}

	}
	public function printResults($model){
		echo("Results for: ".$model."\r\n");
		$queryResults=$this->results[$model];
		foreach($queryResults as $query => $queryResult){
			echo("Query:".$query."\r\n");
			echo("F1:".$queryResult->f1Score."\r\n");
			echo("Recall:".$queryResult->recall."\r\n");
			echo("Precision:".$queryResult->precision."\r\n");
		}
	}
	public function printAvg($model){
		echo("Using model: ".$model."\r\n");
		echo("Avg F1: ".$this->avgF1[$model]."\r\n");
		echo("Avg Recall: ".$this->avgRecall[$model]."\r\n");
		echo("Avg Precision: ".$this->avgPrecision[$model]."\r\n");
	}
	
	public function printTopTen($model){
		echo("Results for: ".$model."\r\n");
		$queryResults=$this->results[$model];
		
		foreach($queryResults as $query => $queryResult){
			echo("Query:".$query."\r\n");
			//var_dump($queryResult->ranks);
			for($i=0;$i < 10;$i++){
				echo $i.": ".$queryResult->ranks[$i]."\r\n";
			}
		}
	}
}

?>